<template>
  <div class="box">
    <h2>UNI-ADMIN</h2>
    <el-form label-width="80px" :model="formLabelAlign">
      <el-form-item>
        <el-input
          v-model="formLabelAlign.name"
          placeholder="请输入账号"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-input
          v-model="formLabelAlign.pas"
          placeholder="请输入密码"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="go">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>


<script>
export default {
  data() {
    return {
      formLabelAlign: {
        name: "",
        pas: "",
      },
    };
  },
  methods: {
    // go() {
    //   this.$axios
    //     .post("http://ceshi5.dishait.cn/admin/login", {
    //       username: this.formLabelAlign.name,
    //       password: this.formLabelAlign.pas,
    //     })
    //     .then((res) => {
    //       console.log(res);
    //       console.log(res.data.data.token);
    //       localStorage.setItem("token",res.data.data.token);
    //       this.$router.push('/user')
    //     })
    //     .catch((err) => {
    //       alert("账号或密码错误")
    //     });
    // },

    go() {
      this.$http(
        "/admin/login",
        "post",
        {
          username: this.formLabelAlign.name,
          password: this.formLabelAlign.pas,
        },
        {}
      )
        .then((res) => {
          console.log(res);
          console.log(res.data.token);
          if (res.msg == "ok") {
            localStorage.setItem("token", res.data.token);
            this.$router.push("/user");
          }
        })
        .catch((err) => {
          alert("账号或密码错误");
        });
    },
  },
};
</script>


<style lang="scss" scoped>
.box {
  width: 500px;
  height: 400px;
  margin: 200px auto;
  h2 {
    // color: white;
    text-align: center;
  }
}
</style>
